package com.singzi.leetcode.N800;

import java.util.Arrays;
import java.util.Deque;
import java.util.LinkedList;

public class T0739 {
    public static void main(String[] args) {
        int []nums = {73,74,75,71,69,72,76,73};
        Solution0379 solution0379 = new Solution0379();
        System.out.println(Arrays.toString(solution0379.dailyTemperatures(nums)));
    }
}
class Solution0379 {
    public int[] dailyTemperatures(int[] temperatures) {
        int []ans = new int[temperatures.length];
        Deque<Integer> stack = new LinkedList<Integer>();
        for(int i = 0;i < temperatures.length;i++){
            while (!stack.isEmpty() && temperatures[i] > temperatures[stack.peek()]){
                int index = stack.pop();
                ans[index] = i-index;
            }
            stack.push(i);
        }
        return ans;

    }
}